import Vue from 'vue'
import App from './App'
import store from './store'
import Vuex from 'vuex'
import router from './router'
import ElementUI from 'element-ui'
import request from '@/api/request'
import 'element-ui/lib/theme-chalk/index.css' //elmentui样式
import Pagination from '_c/Pagination' //分页组件
Vue.prototype.request = request
Vue.prototype.$refresh = false

Vue.use(Vuex)
Vue.use(ElementUI, {size: 'mini'})
//注册全局组件
Vue.component('pagination', Pagination)//分页组件

Vue.config.productionTip = false;
// 路由守卫，进入每个路由前都会执行该方法
router.beforeEach((to, from, next) => {
    let path = to.path;
    // next()

    const userInfo = store.getters.userInfo
    if (path.includes('/sys')) {
        if ((userInfo&&userInfo.sysRole)) {
            next()
        } else {
            next("404")
        }
    } else {
        next()
    }
    // if (path == "/401" || path == "/404" || path == "/500") {
    //     next()
    // }else if (to.query && to.query.accesstoken) {//第一次访问
    // } else {
    //     next("401")
    // }
    // if (path.includes('/sys')&& !from.path.includes('/sys')) {
    //     setTimeout(() =>{
    //         location.reload()
    //     },100)
    // }
    if (from.path.includes('/sys')&&!path.includes('/sys')) {
        setTimeout(()=> {
            location.reload()
        },100)
    }
})
window.vue = new Vue({
    store,
    router,
    render: h => h(App)
});
window.vue.$mount('#app');
